<?php
$tuit_total = 0.00;
$matr_total = 0.00;
$misc_total = 0.00;
$othe_total = 0.00;
?>
<div class="row">
<div class="large-12 columns">
	<?=$system_message;?>
		
		<?php if($guidance_recommendation): ?>
		<legend class="label">Guidance Recommendation</legend>
		<hr class="clearfix">
		<div class="alert alert-info">
			<b>Recommendation:</b>&nbsp;<?php echo $guidance_recommendation->guidance_recommendation; ?>
		</div>
		<br class="clearfix">
		<?php endif; ?>
	
	<div class="panel"><h6>View Student Financial Records</h6></div>
	<!--  start here  -->
		<div>
		
		<legend class="label">Financial Records</legend>
		<hr class="clearfix">
		
		<div class="alert alert-info">
			<b>Payment Mode:</b>
			<?if($payment_mode):?>
				<a href="#" data-reveal-id="view_payment_mode" class="btn"><i class="icon-asterisk"></i><?=$payment_mode->payment_mode;?></a>
				<?if($menu_true == TRUE):?>
					<a href="<?=site_url('fees/set_payment_mode/'.$enrollment_id.'/'.$authlink);?>" class="btn btn-link">Change Payment Plan</a>
				<?endif;?>
			<?else:?>
				<button class="btn"><i class="icon-exclamation-sign"></i> No Payment Plan</button>
				<?if($menu_true == TRUE):?>
					<a href="<?=site_url('fees/set_payment_mode/'.$enrollment_id.'/'.$authlink);?>" class="btn btn-link">Set Payment Plan</a>
				<?endif;?>
			<?endif;?>
		</div>
		
		<br class="clearfix">
		
		<table class="table table-striped table-hover">
			<thead>
				<?if($menu_true):?>
				<tr>
					<td colspan="3">
						<div class="btn-group">
							<!--
							<a href="<?php echo site_url('fees/billing_form').'/'.__link(intval($enrollment_id));?>" class="btn btn-small confirm" title="Confirm/Create Billing Form?">Billing Form</a>
							-->
							<a href="<?php echo site_url('fees/add_payment_record').'/'.$enrollment_id.'/'.$authlink;?>" class="btn btn-small  confirm" title="Add a Payment Record for the student?"><i class="icon-plus"></i>&nbsp;&nbsp;&nbsp;Add Payment</a>
							<a href="<?=site_url('fees/payment_record/'.$enrollment_id);?>" class="btn btn-small " title="View Payment Record of the student?"><i class="icon-pencil"></i>&nbsp;&nbsp;&nbsp;Payment Record</a>
						</div>
						
						<div class="btn-group">
							<a href="<?php echo site_url('fees/add_fee_manually').'/'.$enrollment_id.'/'.$authlink;?>" class="btn btn-small confirm" title="Do you want to add fee for student?">Add Miscellaneous Fee</a>
							<?php if($enrollee_type == 'new'): ?>
							<a href="" data-reveal-id="guidance-reccomendation-modal-menu" class="btn btn-small">Guidance Recommendation</a>
							<?php endif; ?>
							<a href="" data-reveal-id="penalty-assessment-modal-menu" class="btn btn-small">Penalty Assessment</a>
						</div>
						<?php
						if($enrollee_data->nationality!='Filipino'){
						?>
						<div class="btn-group"><a href="" data-reveal-id="foreign-fee-modal" class="btn btn-small">Foreign Fee</a></div>
						<?php
						}
						?>

						<div class="btn-group">
							<a href="<?=site_url('fees/recompute_fee/'.__link(intval($enrollment_id)));?>" class="confirm btn btn-small btn-success" title="Are you sure you want to recalculate fees for this student?"><i class=" icon-refresh"></i>&nbsp;Recompute Student Fees.</a>	
							<a href="<?=site_url('fees/p/'.$enrollment_id.'/'.$authlink);?>" class="btn btn-small " target="_blank" title="Print?"><i class="icon-print"></i>&nbsp;&nbsp;&nbsp;Print</a>							
						</div>
					</td>	
				</tr>
				<?endif;?>
				<tr>
					<th>Name of Fee</th>
					<th>Amount</th>
					<th>&nbsp;</th>
				</tr>
				</thead>
				<tbody>
					<?if($tuit_fees OR $misc_fees OR $cca_fees):?>
					<!-- tuition fees-->
					<tr>
						<td colspan="3"><span class="label">Tuition Fee:</span></td>
					</tr>
					<?if(!empty($tuit_fees)):?>
						<?foreach($tuit_fees as $key => $value):?>
						<tr>
							<td class="fee_content"><?=$value->sef_fee_name;?></td>
							<td style="text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
							<td></td>
						</tr>
						<?php 
						$tuit_total = $tuit_total + $value->sef_fee_rate;
						?>
						<?endforeach;?>
					<?else:?>
						<tr>
						<?if($menu_true == TRUE):?>
							<td colspan="3">No tuition Fees set for this level <a href="<?=site_url('fees/check_pull_tuition_fee/'.$enrollment_id.'/'.$authlink);?>"  class="btn btn-mini">Check and Pull Tuition Fee</a></td>
						<?else:?>
							<td colspan="3"> No Tuition Fee Has Been Set For This Grade Level</td>
						<?endif;?>
						</tr>
					<?endif;?>
					<!--end tuition fees-->
					
					<!-- matriculation fees-->
					<tr>
						<td colspan="3"><span class="label">Matriculation Fee:</span></td>
					</tr>
					<?if(!empty($cca_fees)):?>
						<?foreach($cca_fees as $key => $value):?>
						<tr>
							<td class="fee_content"><?=$value->sef_fee_name;?></td>
							<td style="text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
							<td></td>
						</tr>
						<?php
						$matr_total = $matr_total + $value->sef_fee_rate;
						?>
						<?endforeach;?>
					<?else:?>
						<tr>
						<?if($menu_true == TRUE):?>
							<td colspan="3">No matriculation Fees set for this level <a href="<?=site_url('fees/check_pull_cca_fee/'.$enrollment_id.'/'.$authlink);?>"  class="btn btn-mini">Check and Pull Matriculation Fee</a></td>
						<?else:?>
							<td colspan="3"> No Matriculation Fee Has Been Set For This Grade Level</td>
						<?endif;?>
						</tr>
					<?endif;?>
					<!--end matriculation fees-->
					
					<!-- Miscellaneous fees-->
					<tr>
						<td colspan="3"><span class="label">Other School Fees:</span></td>
					</tr>
					<?if(!empty($misc_fees)):?>
						<?foreach($misc_fees as $key => $value):?>
						<tr>
							<td class="fee_content"><?=$value->sef_fee_name;?></td>
							<td style="text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
							<? echo $delete_link($value->sef_id,$enrollment_id,$authlink);?>
						</tr>
						<?php
						$misc_total = $misc_total + $value->sef_fee_rate;
						?>
						<?endforeach;?>
					<?else:?>
					<tr>
					<?if($menu_true == TRUE):?>
						<td colspan="3">No Other School Fees set for this level <a href="<?=site_url('fees/check_pull_miscellaneous_fee/'.$enrollment_id.'/'.$authlink);?>" class="btn btn-mini">Check and Pull Other School Fee</a></td>
					<?else:?>
						<td colspan="3"> No Other School Fees Has Been Set For This Grade Level.</td>
					<?endif;?>
					</tr>
					<?endif;?>
					<!-- end miscellaneous fees-->
					
					<!-- Student Optional Fees-->
					<tr>
						<td colspan="3"><span class="label">Miscellaneous Fees:</span></td>
					</tr>
					<?if(!empty($other_fees)):?>
						<?foreach($other_fees as $key => $value):?>
							<tr>
								<td class="fee_content"><?=$value->sef_fee_name;?></td>
								<td style="text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
								<? echo $delete_link($value->sef_id,$enrollment_id,$authlink);?>
							</tr>
							<?php
							$othe_total = $value->sef_fee_rate;
							?>
						<?endforeach;?>
					<?else:?>
							<tr>
								<td colspan="3" style="text-align:center;">
								No Fees.
							</td>	
							</tr>
					<?endif;?>
					<!-- end Student Optional Fees-->
					
					<tr>
						<td colspan="3" style="text-align:center;">
							<!-- table Break--><br/>
						</td>	
					</tr>
					
					<tr class="bordered">
						<td>Tuition Fee + Matriculation Fee + Other School Fees</td>
						<td>&nbsp;</td>
						<td style="text-align:right;">&#8369; <?php echo money($tuit_total + $matr_total + $misc_total);?></td>
					</tr>
					<tr class="bordered">
						<td>Miscellaneous Fees</td>
						<td style="text-align:right;"><span style="font-size:20px;font-weight:bold;">+</span></td>
						<td style="text-align:right;">&#8369; <strong><?=money($othe_total);?> </strong></td>
					</tr>
					<!-- end list of discounts-->
					<!-- discounts total -->
					<tr class="noborder-btm">
						<td>
							<ul style="list-style-type:none;">
							<?if(!empty($student_scholarships)):
								$count = 1;
								foreach($student_scholarships as $sc): ?>
									<li class="items-list">
										<a href="<?=site_url('fees/delete_scholarship/'.__link(intval($enrollment_id),intval($sc->sch_id)));?>" class="btn btn-warning btn-mini confirm" title="delete deduction?">x</a>
										<?=$count.') '.ucwords($sc->scholarship_name);?>
									</li>
								<? 
								$count++;
								endforeach;?>
							<?endif;?>
							<?if(!empty($student_deductions)):?>
								<?
								$count = 1;
								foreach($student_deductions as $sd): ?>
									<li class="items-list">
										<a href="<?=site_url('fees/delete_deduction/'.__link(intval($enrollment_id),intval($sd->sdr_id)));?>" class="btn btn-warning btn-mini confirm" title="delete deduction?">x</a>
										<a href="<?=site_url('fees/edit_deduction/'.__link(intval($enrollment_id),intval($sd->sdr_id)));?>" class="btn btn-info btn-mini confirm" title="edit deduction?">e</a>
										<?=$count.') '.ucwords($sd->sdr_remarks);?>
									</li>
								<? 
								$count++;
								endforeach;?>
							<?endif;?>
							</ul>
						</td>
						<td></td>
						<td style="text-align:right;">
							<ul style="list-style-type:none;">
							<?if(!empty($student_scholarships)):?>
								<? foreach($student_scholarships as $sc): ?>
									<li><i><?=money($sc->total_value_deducted);?></i></li>
								<? endforeach;?>
							<?endif;?>
							<?if(!empty($student_deductions)):?>
								<? foreach($student_deductions as $sd): ?>
									<li><i><?=money($sd->sdr_amount);?></i></li>
								<? endforeach;?>
							<?endif;?>
							</ul>
						</td>
					</tr>
					<!-- end discounts total -->
					<tr class="noborder-top">
						<td>Deductions and Scholarships (total)  <?echo $add_edit_deductions($enrollment_id,$authlink);?></td>
						<td style="text-align:right;"><span style="font-size:20px;font-weight:bold;">-</span></td>
						<td style="text-align:right;">&#8369;  <strong style="color:#164307;"><?=money($total_stud_deductions);?> </strong></td>
					</tr>
					<tr class="bordered">
						<td>Sub Total:</td>
						<td style="text-align:right;"><span style="font-size:20px;font-weight:bold;">=</span></td>
						<td style="text-align:right;color:#f00;">&#8369;  <strong><?php echo money(round($sum_amount_due + @$electives_total,2));?> </strong></td>
					</tr>
					<tr class="bordered">
						<td>Total Amount Paid</td>
						<td style="text-align:right;"><span style="font-size:20px;font-weight:bold;">-</span></td>
						<td style="text-align:right;color:#0640AA;">&#8369;  <strong><?php echo money(round($sum_paid_fees,2));?> </strong></td>
					</tr>
					<tr class="bordered">
						<td>Total amount Due:</td>
						<td style="text-align:right;"><span style="font-size:20px;font-weight:bold;">=</span></td>
						<td style="text-align:right;color:#f00;">&#8369;  <strong><?php echo money(round(($sum_amount_due + @$electives_total) - $sum_paid_fees,2));?> </strong></td>
					</tr>
				<?else:?>
					<tr class="info">
						<td colspan="3">
							<strong>A small error has occurred. System cannot find fees set for student.</strong>
							<ul style="list-style-type:none;">
								<li>Possible Cause:</li>
								<li><i class="icon-hand-right"></i>&nbsp;Grade Level has no set of payments.</li>
							</ul>
							<a href="<?=site_url('fees/generate_student_fees/'.__link($enrollment_id));?>" class="confirm btn btn-success btn-mini" title="Proceed and generate student fees?">Check and Generate Student Fee</a>
						</td>
					</tr>
				<?endif;?>
				</tbody>
			
		</table>
		
		
		</div>
	<!--  end here  -->
</div>
</div>
